class: center, middle, inverse, title-slide .title[ # Getting map data into R ] --- layout: true <div class="dk-footer"> <span> <a href="https://rfortherestofus.com/" target="_blank">R for the Rest of Us </a> </span> </div> --- class: center, middle, dk-section-title background-image:url("images/globe-background.jpg") background-size: contain # Making maps is complex --- ## R for maps R has packages for every part of the mapping workflow: .pull-left[ - importing map data - wrangling and cleaning map data - computing geographic distances, areas, intersections and more.. - visualising map data ] .pull-right[ <img src='images/sf-logo.gif' width="40%"> <img src='images/mapview-logo.gif' width="40%"> ] --- ## Maps flatten a complex world (I) .pull-left[
] .pull-right[ <!-- --> ] --- .pull-left[ <blockquote class="twitter-tweet"><p lang="en" dir="ltr">Animating the Mercator projection to the true size of each country in relation to all the others.<br><br>Focusing on a single country helps to see effect best.<a href="https://twitter.com/hashtag/dataviz?src=hash&ref_src=twsrc%5Etfw">#dataviz</a> <a href="https://twitter.com/hashtag/maps?src=hash&ref_src=twsrc%5Etfw">#maps</a> <a href="https://twitter.com/hashtag/GIS?src=hash&ref_src=twsrc%5Etfw">#GIS</a> <a href="https://twitter.com/hashtag/projectionmapping?src=hash&ref_src=twsrc%5Etfw">#projectionmapping</a> <a href="https://twitter.com/hashtag/mapping?src=hash&ref_src=twsrc%5Etfw">#mapping</a> <a href="https://t.co/clpCiluS1z">pic.twitter.com/clpCiluS1z</a></p>— Neil Kaye (@neilrkaye) <a href="https://twitter.com/neilrkaye/status/1050740679008296967?ref_src=twsrc%5Etfw">October 12, 2018</a></blockquote> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script> ] .pull-right[ Jakub Nowosad replicated this GIF in `{ggplot2}` on their blog: [nowosad.github.io/post/maps-distortion](http://nowosad.github.io/post/maps-distortion) ] --- ## All maps are wrong... .pull-left[ <iframe width="675" height="406" src="https://www.youtube.com/embed/kIID5FDi2JQ" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe> ] .pull-right[ All map projections distort the surface of the Earth to some extent. Some regions or countries may be better represented with specific projections. ] ??? --- ### ... but CRS 4326 is a good default The Coordinate Reference System (CRS) of a geospatial dataset specifies the projection of the dataset. ??? --- ### ... but CRS 4326 is a good default The Coordinate Reference System (CRS) of a geospatial dataset specifies the projection of the dataset. - WGS84 is the most common [geographic] CRS used in the world. - It's more usually referred to by the EPSG code 4326 - This "magic number" will appear often in our code ```r quakes %>% st_as_sf(coords = c("long", "lat"), crs = 4326) %>% mapview() ``` ??? --- ## Maps flatten a complex world (II) .pull-left[ <center> <img src='images/disputed-territories.png' width="400px"> </center> ] .pull-right[ - There are more than 100 territorial disputes. - There are more than 30 naming disputes, including seas and other bodies of water. - Making maps is political, consider your audience and intent. ] <br> <br> Interactive dispute map: [metrocosm.com/disputed-territories-map](http://metrocosm.com/disputed-territories-map.html) ??? --- ## Maps flatten a complex world (III) Base maps (or map tiles) live behind the data we add to our maps and add flavour to the map. .pull-left[ <center>
</center> ] .pull-right[ <center>
</center> ] ??? --- ## Maps flatten a complex world (III) .pull-left[ <center>
</center> ] .pull-right[
] ??? --- ## Maps flatten a complex world (IV) Sometimes the maps we want to build require us to manipulate the relative positions of regions. .pull-left[ <center> <img src="data:image/png;base64,#01_02_making-maps-is-complex_files/figure-html/unnamed-chunk-13-1.png" width="350px" /> </center> ] .pull-right[ <center> <img src="data:image/png;base64,#01_02_making-maps-is-complex_files/figure-html/unnamed-chunk-15-1.png" width="350px" /> </center> ] ??? --- class: center, middle, dk-section-title background-image:url("images/desk-office-pen-ruler.jpg") background-size: contain ## Are maps worth it? ??? --- ### Choropleth are the gold standard for election data .pull-left[ <!-- --> ] .pull-right[ <!-- --> ] ??? --- ## Maps show where things happen <center>
</center> ??? --- ## R is a complete GIS system .pull-left[ Software designed to work with geospatial data is called GIS (Geospatial Information System) software. Most dedicated GIS tools are expensive and extremely technical to use. R is without doubt a complete and powerful GIS system. We can use it to map or manipulate any and all geospatial datasets. ] .pull-right[ <br> <br> <center> <img src='images/sf-logo.gif' width="40%"> <img src='images/mapview-logo.gif' width="40%"> </center> ] ???